<?php

/*
+--------------------------------------------------------------------------
|   Invision Power Board
|   =============================================
|   by Matthew Mecham
|   (c) 2001 - 2006 Invision Power Services, Inc.
|   
|   =============================================
|   
|   
+---------------------------------------------------------------------------
|   > $Date: 2008-08-03 12:27:54 -0400 (Mon, 03 Aug 2008) $
|   > $Revision: 01 $
|   > $Author: BabyWolf $
+---------------------------------------------------------------------------
|
|   > TASK SCRIPT: Update HP
|   > Script written by BabyWolf
|   > Date started: 03rd August 2008 (12:27)
|
+--------------------------------------------------------------------------
*/

//-----------------------------------------
// THIS TASKS OPERATIONS:
// Update hp for member everyday
//+----------------------------------------

if ( ! defined( 'IN_IPB' ) )
{
	print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded all the relevant files.";
	exit();
}

class task_item
{
	var $class     = "";
	var $root_path = "";
	var $task      = "";
	
	/*-------------------------------------------------------------------------*/
	// Our 'auto_run' function
	// ADD CODE HERE
	/*-------------------------------------------------------------------------*/
	
	function run_task()
	{
		// Decrease member hp if they didn't visit our site today
		// Build set string
		$setStr = 'field_'.$this->ipsclass->vars['dkm_hpid']."=".'field_'.$this->ipsclass->vars['dkm_hpid']."-".$this->ipsclass->vars['dkm_hpdpd'];
		// Construct whole query
		$this->ipsclass->DB->simple_construct(array('update' 	=> 'pfields_content',
													'set'		=> $setStr,
													'where'		=> 'field_'.$this->ipsclass->vars['dkm_hpid'].'>='.$this->ipsclass->vars['dkm_hpdpd'],
													)
												);
		$this->ipsclass->DB->simple_exec();
		
		// Increase member hp if they visit our site today
		// Build set string
		$setStr = 'pfc.field_'.$this->ipsclass->vars['dkm_hpid']."=pfc.field_".$this->ipsclass->vars['dkm_hpid']."+".$this->ipsclass->vars['dkm_hpipday'];
		// Build condition string
		$less_than = time() - 86400;
		$whereStr = "pfc.member_id IN (SELECT m.id FROM ".$this->ipsclass->DB->obj['sql_tbl_prefix']."members as m WHERE m.last_visit > ".$less_than.")";
		// Construct whole query 
		$this->ipsclass->DB->simple_construct(array('update' 	=> 'pfields_content as pfc',
													'set'		=> $setStr,
													'where'		=> $whereStr,
													)
												);
												
		$this->ipsclass->DB->allow_sub_select = 1;
		$this->ipsclass->DB->simple_exec();
		$this->class->unlock_task( $this->task );
		$this->class->append_task_log( $this->task, 'Member HP updated.' );
				
		//-----------------------------------------
		// Unlock Task: DO NOT MODIFY!
		//-----------------------------------------
		
		$this->class->unlock_task( $this->task );
	}
	
	/*-------------------------------------------------------------------------*/
	// register_class
	// LEAVE ALONE
	/*-------------------------------------------------------------------------*/
	
	function register_class(&$class)
	{
		$this->class     = &$class;
		$this->ipsclass  =& $class->ipsclass;
		$this->root_path = $this->class->root_path;
	}
	
	/*-------------------------------------------------------------------------*/
	// pass_task
	// LEAVE ALONE
	/*-------------------------------------------------------------------------*/
	
	function pass_task( $this_task )
	{
		$this->task = $this_task;
	}
	
	
}
?>